from flask_restful import fields

from app.utils import SimpleDateField

banners_fields = {
    'id': fields.Integer,
    'image_url': fields.String,
    'json_data': fields.String,
    'category': fields.String
}

branches_fields = {
    'id': fields.Integer,
    'name': fields.String,
    'address': fields.String
}

category_fields = {
    'id': fields.Integer,
    'name': fields.String,
    'pic_url': fields.String,
    'sort': fields.Integer,
}

goods_sku_stock_fields = {
    'id': fields.Integer,
    'sku_id': fields.Integer,
    'stock': fields.Integer,
    'exchange_num': fields.Integer,
    'sku_sn': fields.String(attribute='sku.sku_sn'),
    'price':  fields.Integer(attribute='sku.price'),

}

goods_info_fields = {
    'id': fields.Integer(attribute="goods.id"),
    'name': fields.String(attribute="goods.name"),
    'detail': fields.String(attribute="goods.detail"),
    'pic_url': fields.String(attribute="goods.pic_url"),
    'exchange_price': fields.Integer(attribute="goods.exchange_price"),
    'total_num': fields.Integer(attribute="goods.total_num"),
    'barcode': fields.String(attribute="goods.barcode"),
    'images': fields.List(fields.Nested(
        {
            'id': fields.Integer(attribute="id"),
            'url': fields.String(attribute="url"),
            'width': fields.Integer(attribute="width"),
            'height': fields.Integer(attribute="height")
        }
    ), attribute='goods.images'),
    'is_online': fields.Integer(attribute="goods.is_online"),
    'online_time': fields.String(attribute="goods.online_time"),
    'period': fields.Integer(attribute="goods.period"),
    'required_number': fields.Integer(attribute="goods.required_number"),
    'tags': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'name': fields.String
        }
    )),
    'sku': fields.List(fields.Nested({
        'id': fields.Integer,
        'sku_id': fields.Integer,
        'stock': fields.Integer,
        'exchange_num': fields.Integer,
        'sku_sn': fields.String(attribute='sku.sku_sn'),
        'price':  fields.Integer(attribute='sku.price'),
        'cover':  fields.String(attribute='sku.cover'),
        'suk_name': fields.String(attribute='sku.suk_name')
    }), attribute='sku_stock'),
    'sku_attrs': fields.List(fields.Nested({
        'k_id': fields.Integer,
        'k_name': fields.String,
        'value_list': fields.List(fields.Nested({
            'v_id': fields.Integer,
            'v_name': fields.String
        }))
    }), attribute='sku_attrs'),
    'fee_template': fields.Nested({
        'id': fields.Integer,
        'name': fields.String,
        'base_fee': fields.Integer,
        'add_fee': fields.Integer
    }, attribute='goods.fee_template')
}

goods_info_list_fields = {
    'id': fields.Integer(attribute='goods.id'),
    'name': fields.String(attribute='goods.name'),
    'brand_id': fields.Integer(attribute='goods.brand_id'),
    'brand_name': fields.String(attribute='goods.brand.name'),
    # 'brand': fields.Nested({
    #     'id': fields.Integer,
    #     'name': fields.String
    # }),
    'category_id': fields.Integer(attribute='goods.category_id'),
    'category': fields.Nested({
        'id': fields.Integer,
        'name': fields.String
    }, attribute='goods.category'),
    'category_name': fields.String(attribute='goods.category.name'),
    'secondary_category_id': fields.Integer(attribute='goods.secondary_category_id'),
    'secondary_category_name': fields.String(attribute='goods.secondary_category.name'),
    'detail': fields.String(attribute='goods.detail'),
    'pic_url': fields.String(attribute='goods.pic_url'),
    'exchange_price': fields.Integer(attribute='goods.exchange_price'),
    'total_num': fields.Integer(attribute='goods.total_num'),
    'barcode': fields.String(attribute='goods.barcode'),
    'images': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'url': fields.String,
            'width': fields.Integer,
            'height': fields.Integer
        }
    ), attribute='goods.images'),
    'tags': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'name': fields.String
        }
    ))
}

goods_fields = {
    'id': fields.Integer,
    'name': fields.String,
    'detail': fields.String,
    'pic_url': fields.String,
    'exchange_price': fields.Integer,
    'total_num': fields.Integer,
    'barcode': fields.String,
    'images': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'url': fields.String,
            'width': fields.Integer,
            'height': fields.Integer
        }
    )),
    'is_online': fields.Integer,
    'online_time': fields.String,
    'period': fields.Integer,
    'required_number': fields.Integer,
}

goods_list_fields = {
    'id': fields.Integer,
    'name': fields.String,
    'brand_id': fields.Integer,
    'brand': fields.Nested({
        'id': fields.Integer,
        'name': fields.String
    }),
    'category_id': fields.Integer,
    'category': fields.Nested({
        'id': fields.Integer,
        'name': fields.String
    }),
    'category_name': fields.String(attribute='category.name'),
    'secondary_category_id': fields.Integer,
    'secondary_category_name': fields.String(attribute='secondary_category.name'),
    'detail': fields.String,
    'pic_url': fields.String,
    'exchange_price': fields.Integer,
    'total_num': fields.Integer,
    'barcode': fields.String,
    'images': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'url': fields.String,
            'width': fields.Integer,
            'height': fields.Integer
        }
    ))
}

user_fields = {
    'id': fields.Integer,
    'uid': fields.String,
    'nickname': fields.String,
    'avatar': fields.String,
    # 'branch': fields.Nested(branch_fields),
    'branch_id': fields.Integer,
    'branch_name': fields.String(attribute="branch.name"),
    'doll': fields.Integer,
    'status': fields.Boolean,
    'gender': fields.Integer,
    'created': SimpleDateField,
}


order_list_fields = {
    'id': fields.Integer,
    'order_no': fields.String,
    'goods_name': fields.String(attribute='goods.name'),
    'order_time': SimpleDateField,
    'exchange_type': fields.Integer,
    'status': fields.Integer,
    'amount': fields.Integer,
    'unit_price': fields.Integer,
    'total_price': fields.Integer,
    'avatar': fields.String(attribute="user.avatar"),
    'pic_url': fields.String(attribute='goods.pic_url'),
    'remark': fields.String,
    'tags': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'name': fields.String
        }
    ), attribute='goods.tags'),
    'cover': fields.String(attribute='order_sku.sku.cover'),
    'sku_attrs': fields.List(fields.Nested({
        'k_id': fields.Integer,
        'k_name': fields.String,
        'v_id': fields.Integer,
        'v_name': fields.String
    }), attribute='order_sku.sku.attrs'),
}


order_fields = {
    'id': fields.Integer,
    'order_no': fields.String,
    'goods_name': fields.String(attribute='goods.name'),
    'user_id': fields.Integer,
    'branch_name': fields.String(attribute="branch.name"),
    'order_time': SimpleDateField,
    'exchange_type': fields.Integer,
    'status': fields.Integer,
    'amount': fields.Integer,
    'unit_price': fields.Integer,
    'total_price': fields.Integer,
    'address': fields.Nested({
        'id': fields.Integer,
        'name': fields.String,
        'phone': fields.String,
        'address': fields.String,
        'province': fields.String,
        'city': fields.String,
        'county': fields.String
    }),
    'remark': fields.String,
    'pic_url': fields.String(attribute='goods.pic_url'),
    'courier_company': fields.String,
    'courier_no': fields.String,
    'tags': fields.List(fields.Nested(
        {
            'id': fields.Integer,
            'name': fields.String
        }
    ), attribute='goods.tags'),
    'cover': fields.String(attribute='order_sku.sku.cover'),
    'sku_attrs': fields.List(fields.Nested({
        'k_id': fields.Integer,
        'k_name': fields.String,
        'v_id': fields.Integer,
        'v_name': fields.String
    }), attribute='order_sku.sku.attrs'),
}


lastest_order_fields = {
    'id': fields.Integer,
    'nickname': fields.String(attribute='user.nickname'),
    'avatar': fields.String(attribute='user.avatar'),
    'goods_name': fields.String(attribute='goods.name'),
    'order_time': SimpleDateField,
}


rank_fields = {
    'user_id': fields.Integer,
    'nickname': fields.String,
    'avatar': fields.String,
    'doll': fields.Integer,
    'rank': fields.Integer
}


sponsor_records_fields = {
    'id': fields.Integer,
    'from_id': fields.Integer,
    'from_name': fields.String,
    'to_id': fields.Integer,
    'to_name': fields.String,
    'doll': fields.Integer,
    'created': SimpleDateField
}


doll_records_fields = {
    'id': fields.Integer,
    'user_id': fields.Integer,
    'type': fields.Integer,
    'doll': fields.Integer,
    'created': SimpleDateField
}


address_fields = {
    'id': fields.Integer,
    'user_id': fields.Integer,
    'name': fields.String,
    'phone': fields.String,
    'address': fields.String,
    'province': fields.String,
    'city': fields.String,
    'county': fields.String,
    'area_code': fields.String,
    'alias': fields.String,
    'deleted': fields.Boolean,
    'is_default': fields.Boolean
}
